<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="24" :offset="0">
        <el-card shadow="always" :body-style="{ padding: '20px' }">
          <template #header>
            <div>
              <span>网站访问量</span>
            </div>
          </template>
          <div class="chart" id="line">
            <!-- 折线图 -->
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="12" :offset="0">
        <el-card shadow="always" :body-style="{ padding: '20px' }">
          <template #header>
            <span>家具分类统计</span>
          </template>
          <div class="chart" id="bar">
            <!-- 柱状图 -->
          </div>
        </el-card>
      </el-col>
      <el-col :span="12" :offset="0">
        <el-card shadow="always" :body-style="{ padding: '20px' }">
          <template #header>
            <div>
              <span>客户群体城市</span>
            </div>
          </template>
          <div class="chart" id="pie">
            <!-- 饼状图 -->
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import * as echarts from "echarts"; //引入echarts提供所有方法
import { onMounted } from "vue";
import bar from "./options/bar";
import line from "./options/line";
import pie from "./options/pie";
import { pieGet } from "../../service/api/dashboard";
// onMounted生命周期会等到DOM渲染出来后再执行
onMounted(async () => {
  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById("bar"));
  // 绘制图表
  myChart.setOption(bar);

  //绘制折线图
  var lineChart = echarts.init(document.getElementById("line"));
  lineChart.setOption(line);

  //绘制饼状图
  var pieChart = echarts.init(document.getElementById("pie"));
  let data = await pieGet();
  pie.series[0].data = data; //在setOption之前，修改图表配置项
  pieChart.setOption(pie);
});
</script>

<style lang="scss" scoped>
.chart {
  height: 230px;
  /* border: 1px solid red; */
}
</style>
